package com.zws.cucumber.util.cass;

import com.datastax.oss.driver.api.core.CqlSession;
import org.apache.commons.lang3.StringUtils;
import org.cassandraunit.CQLDataLoader;

public class ZwsCassContext {

    public static final String DEFAULT_HOST_IP = "127.0.0.1";
    private static CqlSession session;
    private static ZwsCassTemplate cassTemplate;
    private static CQLDataLoader dataLoader;

    private static boolean isInit = false;
    private static int cassandraPort = 9042;
    private static final String localDc = "datacenter1";
    private static final String defaultCreateTablePath = "cql/create-table.cql";
    private static final String defaultDataPath = "cql/data.cql";
    private static final int maxTryTimes = 3;


    public static int getCassandraPort() {
        if (!isInit) {
            throw new RuntimeException("Embedded Cassandra not started yet");
        }
        return cassandraPort;
    }

    public static CqlSession getSession() {
        return session;
    }

    public static ZwsCassTemplate getCassTemplate() {
        return cassTemplate;
    }

    public static String getGeneratedKeySpace(String keyspace) {
        String keyspaceFromProperty = System.getProperty("keyspace");
        if (StringUtils.isNotBlank(keyspaceFromProperty)) {
            return keyspaceFromProperty;
        }
        String branchName = System.getProperty("branch");
        return StringUtils.isNotBlank(branchName) ? branchName + "_" + keyspace : keyspace;
    }

    public static String getLocalDc() {
        return localDc;
    }
}
